<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改订单')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-erpOrder-edit" th:object="${erpOrder}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">创建类型：</label>
                <div class="col-sm-8">
                    <select name="createType" class="form-control m-b" th:with="type=${@dict.getType('erp_create_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{createType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">销售员：</label>
                <div class="col-sm-8">
                    <input name="salesmanNo" type="hidden" th:field="*{salesmanNo}">
                    <input name="salesmanNoLabel" readonly onclick="openSelectUser()" th:value="*{salesmanNo}" class="form-control" placeholder="点击选择" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">客户pcb源文件：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="pcbFile" th:field="*{pcbFile}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="pcbFile" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">客户编号：</label>
                <div class="col-sm-8">
                    <input name="customerNo" type="hidden" th:field="*{customerNo}">
                    <input name="customerNoLabel" readonly th:value="*{customerNo}" onclick="openSelectCustomer()" placeholder="点击选择" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同编号：</label>
                <div class="col-sm-8">
                    <input name="pactNo" th:field="*{pactNo}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">生产型号：</label>
                <div class="col-sm-8">
                    <input name="modeNo" type="hidden" th:field="*{modeNo}">
                    <input name="modeNoLabel" readonly onclick="openSelectModel()" th:value="*{modeNo}" class="form-control" placeholder="点击选择" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">下单数量：</label>
                <div class="col-sm-8">
                    <input name="pcsNum" th:field="*{pcsNum}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">预报价：</label>
                <div class="col-sm-8">
                    <input name="prePrice" th:field="*{prePrice}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">订单金额：</label>
                <div class="col-sm-8">
                    <input name="orderPrice" th:field="*{orderPrice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">订单状态：</label>
                <div class="col-sm-8">
                    <select name="orderState" class="form-control m-b" th:with="type=${@dict.getType('erp_order_state')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{orderState}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">工序状态：</label>
                <div class="col-sm-8">
                    <select name="processState" class="form-control m-b" th:with="type=${@dict.getType('erp_process_state')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{processState}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">结算方式：</label>
                <div class="col-sm-8">
                    <select name="settleWay" class="form-control m-b" th:with="type=${@dict.getType('erp_settle_way')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{settleWay}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">收款状态：</label>
                <div class="col-sm-8">
                    <select name="receiptState" class="form-control m-b" th:with="type=${@dict.getType('erp_receipt_state')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{receiptState}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">已收款金额：</label>
                <div class="col-sm-8">
                    <input name="hasReceiptCash" th:field="*{hasReceiptCash}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">应收款金额：</label>
                <div class="col-sm-8">
                    <input name="shouldReceiptCash" th:field="*{shouldReceiptCash}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">欠款金额：</label>
                <div class="col-sm-8">
                    <input name="debtCash" th:field="*{debtCash}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">交货时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="deliveryDate" th:value="${#dates.format(erpOrder.deliveryDate, 'yyyy-MM-dd HH:mm:ss')}" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">包装方式：</label>
                <div class="col-sm-8">
                    <select name="packStyle" class="form-control m-b" th:with="type=${@dict.getType('erp_pack_style')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{packStyle}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出货：</label>
                <div class="col-sm-8">
                    <select name="shipType" class="form-control m-b" th:with="type=${@dict.getType('erp_ship_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{shipType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否新单：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isNewOrder_' + dict.dictCode}" name="isNewOrder" th:value="${dict.dictValue}" th:field="*{isNewOrder}" required>
                        <label th:for="${'isNewOrder_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "erp/erpOrder";
        $("#form-erpOrder-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-erpOrder-edit').serialize());
            }
        }

        $("input[name='deliveryDate']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            todayBtn: true,
            todayHighlight: true,
            keyboardNavigation: true,
            minuteStep: 1,
            autoclose: true
        });

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        // 选择销售员
        function openSelectUser() {
            var url = ctx + "../../system/user/pageSelectUser?dataType=salesman";
            var options = {
                title: '选择销售员',
                url: url,
                callBack: doSelectUserSubmit
            };
            $.modal.openOptions(options);
        }

        function doSelectUserSubmit(index, layero) {
            var body = layer.getChildFrame('body', index);
            var userNo = body.find('#userNo').val();
            var userName = body.find('#userName').val();
            layer.close(index);
            if (userNo != "" && userNo != undefined) {
                $("input[name='salesmanNo']").val(userNo);
                $("input[name='salesmanNoLabel']").val(userNo + '-' + userName);
            }
        }

        // 选择客户
        function openSelectCustomer() {
            var url = ctx + "../../erp/erpCustomer/pageSelectCustomer";
            var options = {
                title: '选择客户',
                url: url,
                callBack: doSelectCustomerSubmit
            };
            $.modal.openOptions(options);
        }

        function doSelectCustomerSubmit(index, layero) {
            var body = layer.getChildFrame('body', index);
            var customerNo = body.find('#customerNo').val();
            var companyName = body.find('#companyName').val();
            layer.close(index);
            if (customerNo != "" && customerNo != undefined) {
                $("input[name='customerNo']").val(customerNo);
                $("input[name='customerNoLabel']").val(customerNo + '-' + companyName);
            }
        }

        // 选择型号
        function openSelectModel() {
            var url = ctx + "../../erp/erpModel/pageSelectModel";
            var options = {
                title: '选择生产型号',
                url: url,
                width:1200,
                callBack: doSelectModelSubmit
            };
            $.modal.openOptions(options);
        }

        function doSelectModelSubmit(index, layero) {
            var body = layer.getChildFrame('body', index);
            var modeNo = body.find('#modeNo').val();
            var modeName = body.find('#modeName').val();
            layer.close(index);
            if (modeNo != "" && modeNo != undefined) {
                $("input[name='modeNo']").val(modeNo);
                $("input[name='modeNoLabel']").val(modeNo + '-' + modeName);
            }
        }
    </script>
</body>
</html>